#include "../include/show_chinese.h"

void show_chinese(int x, int y, unsigned char *str, int color, int size)
{
	Init_Font();
	
	Display_characterX(x, y, str, color, size);
	
	UnInit_Font();
}

//清屏函数
void clean(int color, int x_start, int y_start, int width, int height)
{
    int fd = open("/dev/fb0", O_RDWR);
    if(fd < 0)
    {
        perror("open lcd failed");
        exit(1);
    }

    char *addr = mmap(NULL, 800 * 480 * 4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if(addr == NULL)
    {
        perror("mmap failed");
        exit(1);
    }

    int x, y;
    for(y = y_start; y < y_start + height; y++)
    {
        for(x = x_start; x < x_start + width; x++)
        {
            if (x >= 0 && x < 800 && y >= 0 && y < 480) // ȷ����������Ļ��Χ��
            {
                *(addr + (y * 800 + x) * 4) = (char)color; // ������ɫ��32λ��
                *(addr + (y * 800 + x) * 4 + 1) = (char)(color >> 8);
                *(addr + (y * 800 + x) * 4 + 2) = (char)(color >> 16);
                *(addr + (y * 800 + x) * 4 + 3) = (char)(color >> 24);
            }
        }
    }

    munmap(addr, 800 * 480 * 4);
    close(fd);
}

void* show_warning(void *arg)
{          
    pthread_detach(pthread_self());
    
	clean(0x000000, 320, 190, 275, 50);
	
    while(1)
    {
        show_chinese(350, 200, "�������", 0xFF0000, 2);
        sleep(1);
		clean(0x000000, 320, 190, 275, 50);
		sleep(1);
    }
}
